package com.example.project.api.controller;

import com.example.project.api.dto.GoodInfoDTO;
import com.example.project.api.model.TbWin;
import com.example.project.api.service.TbWinService;
import com.example.project.common.tools.R;
import com.example.project.common.tools.ResponseEnum;
import com.example.project.common.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * (win)表控制层
 *
 * @author ZhangHongRui
 */
@RestController
@RequestMapping("/win")
public class TbWinController {

    @Autowired
    private TbWinService tbWinService;

    /**
     * 根据用户ip查询中奖记录
     */
    @GetMapping("/getWinByIp")
    public R getWinByIp(HttpServletRequest request) {
        String ip = Utils.getIpAddr(request);
        List<GoodInfoDTO> winList = tbWinService.getWinByIp(ip);
        return new R(ResponseEnum.SUCCESS, winList);
    }

}
